import { View } from "../../../mvc/core/View";
import { BaseItem } from "../common/BaseItem";
import { ObjCreate } from "../common/ObjCreate";
import { ImagesConst } from "../../resource/ImagesConst";
import { Language } from "../../../../extend/language/Language";
import { MuiEvent } from "../../../../com/mui/events/MuiEvent";
import { GlobalClass } from "../../../../com/mui/core/GlobalClass";
import { ItemData } from "../../resource/info/ItemData";
import { SoundManager } from "../../../common/sound/SoundManager";
import { SoundTypeConst } from "../../../common/sound/SoundTypeConst";
import { GButton } from "../../../../com/mui/controls/GButton";
import { GTabBar } from "../../../../com/mui/controls/GTabBar";
import { Vector } from "../../../../__AS3__/vec/Vector";
type int = number;
//class RankRewardView
    
    export  class RankRewardView extends View
    {
        constructor(arg1: Array<any>=null)
        {
            super();
            this._itemArr = new Vector.<BaseItem>();
            this._rewards = arg1;
            this._len = arg1.length;
            this._rewards.sortOn("min", Array.NUMERIC);
            this.initUI();
            return;
        }

        /* internal  */initUI(): void
        {
            var loc1=ObjCreate.createBg(0, 0, 200, 260, this, ImagesConst.ToolTipBg);
            ObjCreate.createBg(5, 37, 190, 218, this);
            this._closeBtn = ObjCreate.createGButton("", 175, 8, 19, 19, this, "CloseButton");
            this._closeBtn.focusEnabled = true;
            this._closeBtn.name = "Window_Btn_Close";
            this._closeBtn.configEventListener(flash.events.MouseEvent.CLICK, this.closeBtnClickHandler);
            this._tabBar = ObjCreate.createGTabBar(10, 15, Language.getArray(200311), 63, 22, this, this.onTabBarChange);
            this.drawItem();
            return;
        }

        /* internal  */onTabBarChange(arg1: MuiEvent=null): void
        {
            this.setItemData();
            return;
        }

        /* internal  */drawItem(): void
        {
            var loc3=null;
            var loc1=0;
            var loc2=0;
            while (loc2 < this._rewards.length) 
            {
                if (this._rewards[loc2].type == this._tabBar.selectedIndex) 
                {
                    if (this._rewards[loc2].max == this._rewards[loc2].min) 
                    {
                        ObjCreate.createGTextField(Language.getStringByParam(200327, this._rewards[loc2].max), 10, loc1 * 50 + 58, 80, 20, this);
                    }
                    else 
                    {
                        ObjCreate.createGTextField(Language.getStringByParam(200327, this._rewards[loc2].min + "-" + this._rewards[loc2].max), 10, loc1 * 50 + 58, 80, 20, this);
                    }
                    ObjCreate.createBg(0, loc1 * 50 + 100, 192, 1, this, ImagesConst.SeptalLine);
                    loc3 = new BaseItem();
                    this._itemBg = GlobalClass.getBitmap(ImagesConst.PackItemBg);
                    loc3.setSize(32, 32);
                    loc3.move(2, 2);
                    this._itemBg.x = 140;
                    this._itemBg.y = loc1 * 50 + 58;
                    loc3.x = this._itemBg.x + 3;
                    loc3.y = this._itemBg.y + 3;
                    addChild(this._itemBg);
                    addChild(loc3);
                    this._itemArr.push(loc3);
                    ++loc1;
                }
                ++loc2;
            }
            return;
        }

        public setItemData(): void
        {
            var loc1=[];
            var loc2=0;
            while (loc2 < this._len) 
            {
                if (this._rewards[loc2].type == this._tabBar.selectedIndex) 
                {
                    loc1.push(this._rewards[loc2]);
                }
                ++loc2;
            }
            loc1.sortOn("min", Array.NUMERIC);
            var loc3=0;
            while (loc3 < this._itemArr.length) 
            {
                this._itemArr[loc3].itemData = new ItemData(loc1[loc3].itemCode);
                this._itemArr[loc3].itemData.itemAmount = loc1[loc3].num;
                ++loc3;
            }
            return;
        }

        protected closeBtnClickHandler(arg1: Object /* flash.events.MouseEvent */): void
        {
            SoundManager.instance.soundPlay(SoundTypeConst.UIclose);
            visible = false;
            return;
        }

        /* internal */ /* var */_closeBtn: GButton;

        /* internal */ /* var */_rewards: Array<any>;

        /* internal */ /* var */_itemBg: Object /* flash.display.Bitmap */;

        /* internal */ /* var */_len: int;

        /* internal */ /* var */_itemArr: Vector.<BaseItem>;

        /* internal */ /* var */_tabBar: GTabBar;
    }
